Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VisualShape2D node #2

Merged
merged 11 commits into from
Jul 4, 2020
Merged

Add VisualShape2D node #2

merged 11 commits into from
Jul 4, 2020

Conversation

Xrayez
Copy link
Contributor

@Xrayez Xrayez commented Jun 29, 2020

Sort of closes godotengine/godot-proposals#1126.

goost-visual-shapes

This is pretty much another implementation of godotengine/godot#16483 (it's been suggested to implement this sort of class outside of Godot core), with a larger set of features:

  • edit polygon-based shapes just like you edit Polygon2D (inheriting Godot's AbstractPolygon2DEditor)

  • the shape can be automatically set from parent node (CollisionShape2D, CollisionPolygon2D, basically any node which have either shape, polygon, or points properties defined), so there's no need to set this via code to match those shapes:

    goost-visual-collision-shapes

  • optionally use Godot's default color for collision shapes debugging and respect the Visible Collision Shapes debug option, if you need to display the shapes of custom-made physics/collision nodes (for instance, not using CollisionShape2D but setting the collision shapes via code), which also helps Collision shapes created through CollisionObject2D APIs are not visible godotengine/godot#36499.

Limitations

  1. ConcavePolygonShape2D is not easy to edit because it uses segments over points. Create intermediate segments in ConcavePolygonShape2D. godotengine/godot#32979 is there to fix this inconsistency, but that's only 4.0 fix. So, please use ConvexPolygonShape2D for polygon editing (triangle, pentagons etc), though it's not limited to convex shapes, concave polygons can also be edited through this class. It may be possible to fix this locally in 3.2, but not high priority. added.

  2. There's no textures support, and probably won't be because this class heavily relies on per-shape drawing implemented in Godot. Use Polygon2D node for that. But you may be able to apply textures via shaders anyways.

Example project

visual_shapes.zip (will be merged to Goost examples once this is merged).

You'll have to checkout the visual-shape-2d branch and compile the module to test this.

Feedback

Suggestions welcome, including the name of the class.

@Xrayez Xrayez added the enhancement Improvement of existing features label Jun 29, 2020
@Xrayez Xrayez added the feature 💡 New feature proposal label Jun 29, 2020
@Xrayez
Copy link
Contributor Author

Xrayez commented Jul 1, 2020

Managed to actually edit concave polygon shapes with this class, and the drawing API of Shape2D happens to draw them as an outline by default (without fill), which is nice.

goost-concave-shapes-draw

(convex polygon shapes are filled in contrast).

@Xrayez
Copy link
Contributor Author

Xrayez commented Jul 3, 2020

Perhaps it would be better to rename this to VisibleShape2D? Because of the Visible Collision Shapes option:

Annotation 2020-07-03 211455

@Xrayez
Copy link
Contributor Author

Xrayez commented Jul 3, 2020

I've been also thinking about VisibleCollisionShape2D to extend CollisionShape2D directly, but given the existence of other nodes (CollisionPolygon2D etc), this wouldn't be flexible anymore (at the current state of PR, you can have any compatible node parent to provide the shape for visualizing).

@Xrayez
Copy link
Contributor Author

Xrayez commented Jul 3, 2020

The only thing left to do is providing a way to conveniently edit the rest of the shapes other than polygon shapes. I've created a proposal at Godot to make this happen on the core side godotengine/godot-proposals#1157, but in any case this is possible to do on the module level, but not high-priority.

Xrayez added a commit to goostengine/goost-examples that referenced this pull request Jul 4, 2020
@Xrayez Xrayez merged commit 168dddd into gd3 Jul 4, 2020
@Xrayez Xrayez deleted the visual-shape-2d branch July 4, 2020 10:44
@Xrayez Xrayez added this to the gd3 milestone Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a Shape2D node to draw 2D shapes
1 participant